<?php
    class Model_berita extends CI_Model{
        public $judul;
        public $more;
        public $pembuat;
        public $status;
        public $gambar;
        function __construct() {
            parent::__construct();
        }
        
        function insert(){
            $data = array(
                "judul"=>$this->judul,
                "more"=>$this->more,
                "pembuat"=>$this->pembuat,
                "status"=>$this->status,
                "gambar"=>$this->gambar
                );
            $this->db->insert('berita',$data);
        }
        
        function select_all(){
            $result = $this->db->get('berita');
            return $result;
        }
        
        function select($kondisi,$limit='',$offset=''){
            $this->db->order_by("tglbuat", "desc");
            $query = $this->db->get_where('berita',$kondisi,$limit,$offset);
            return $query;
        }
        
        function selectbyid($idberita){
            $query = $this->db->get_where('berita',array('idberita'=>$idberita));
            return $query->row();
        }
        
        function query($query){
            $result = $this->db->query($query);
            return $result;
        }
        
        function update($id,$data){
            $this->db->where('idberita', $id);
            $this->db->update('berita', $data); 
        }
        
        function delete($id){
            $this->db->where('idberita', $id);
            $this->db->delete('berita');
        }
        
        function count(){
            $this->db->select_max('idberita');
            $query=$query = $this->db->get('berita');
            return ($query->row()->idberita)+1;
        }
    }
?>
